package IC.Types;

import IC.AST.*;
import IC.SemanticCheckes.SemanticError;

public class ClassType extends Type {
	
	public ClassType(ICClass classAST){
		super(classAST.getName());
		this.super_name = classAST.getSuperClassName();
		this.classAST = classAST;
	}

	public String getSuperName(){
		return this.super_name;
	}
	
	public ICClass getClassNode(){
		return this.classAST;
	}
	
	public String toString(){
		String str = this.getName();
		if (this.classAST.hasSuperClass()){
			try {
				str += ", Superclass ID: "+TypeTable.getClassType(this.super_name).getTypeID();
			} catch (SemanticError se){				
			} 
		}	
		return str;
	}
	
	public boolean subtypeOf(Type t){
		// not a class type	
		if (!(t instanceof ClassType)) {
			return false;		
		}
		if (t == this) {
			return true;
		}
		// don't have a super
		if (this.super_name == null) {
			return false;
		}
		else try{
			return TypeTable.getClassType(super_name).subtypeOf(t);
		} catch (SemanticError se){
			return false;
		}
	}
	
	private String super_name;
	private ICClass classAST;
	
}